package com.mzm.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.stereotype.Service;

import com.mzm.api.CategoryDto;
import com.mzm.api.MzmAdminFacade;
import com.mzm.api.ProductInfoDto;
import com.mzm.api.RecommendationDto;
import com.mzm.domain.ProductInfo;
import com.mzm.domain.Recommendation;

@Service("mzmAdminFacade")
public class AdminManagementFacadeImpl implements MzmAdminFacade {

	@Resource
	private RecommendationManagementService recommendationManagementService;

	@Resource
	private DtoConversions dtoConversions;

	@Autowired
	@Required
	public void setRecommendationManagementService(
			RecommendationManagementService recommendationManagementService) {
		this.recommendationManagementService = recommendationManagementService;
	}

	@Autowired
	@Required
	public void setDtoConversions(DtoConversions dtoConversions) {
		this.dtoConversions = dtoConversions;
	}

	@Override
	public void createCategory(String path) {
		System.out.println("ping");
		recommendationManagementService.createCategory(path);
	}

	@Override
	public CategoryDto getCategoryTree() {
		return recommendationManagementService.getCategoryTree();
	}

	@Override
	public void addProductInfo(String path, ProductInfoDto productInfoDto) {
		ProductInfo productInfo = dtoConversions.convert(productInfoDto);
		recommendationManagementService.createProductInfo(path, productInfo);
	}

	@Override
	public List<ProductInfoDto> getProductInfos(String path) {
		List<ProductInfo> productInfos = recommendationManagementService.getProductInfos(path);
		return dtoConversions.convertProductInfos(productInfos);
	}

	@Override
	public List<RecommendationDto> getRecommendations(Integer productInfoId) {
		List<Recommendation> recommendations = recommendationManagementService
				.getRecommendations(productInfoId);
		return dtoConversions.convertRecommendations(recommendations);
	}

	@Override
	public void updateRecommendation(RecommendationDto recommendationDto) {
		dtoConversions.convert(recommendationDto);
	}

	@Override
	public void addRecommendation(Integer productInfoId, RecommendationDto recommendationDto) {
		Recommendation r = dtoConversions.convert(recommendationDto);
		recommendationManagementService.createRecommendation(productInfoId, r);
	}

	@Override
	public void deleteRecommendation(Integer recommendationId) {
		recommendationManagementService.deleteRecommendation(recommendationId);
	}

	@Override
	public void deleteProductInfo(Integer productInfoId) {
		recommendationManagementService.deleteProductInfo(productInfoId);
	}
}
